<?php
//登入中间件
namespace app\v\middleware;

//TPCache缓存模块
use think\facade\Cache;
//TPCookie门面
use think\facade\Cookie;

class Identity
{
    public function handle($request, \Closure $next)
    {
        //整理数据
        $data = Cookie::get();

        if(empty($data['UUID'])){
            //重定向到指定的URL地址
            return redirect('/v/user/login');
        }else{
            $uuid = $data['UUID'];
            $cache = Cache::get($uuid);
            //判断缓存是否存在
            if(empty($cache)){
                //重定向到指定的URL地址
                return redirect('/v/user/login');
            }
        }
        
        return $next($request);
    }
}